package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"go.uber.org/zap"
	"homepage_srv/homepage"
	"homepage_srv/internal/dao"
	"homepage_srv/internal/svc"
	"smart-health-platforms/pkg"
)

type CartAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartAddLogic {
	return &CartAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartAddLogic) CartAdd(in *homepage.CartAddRequest) (*homepage.CartAddResponse, error) {
	// todo: add your logic here and delete this line
	err := dao.CartCreate(int(in.UserId), int(in.GoodsId), int(in.ShuId), int(in.Num))
	if err != nil {
		pkg.Error("添加购物车失败", zap.Error(err))
		return nil, err
	}
	return &homepage.CartAddResponse{GoodsId: in.GoodsId}, nil
}
